/*
 *  MiloLoadTextDatabase.cpp
 *  Milovo04alfa01
 *
 *  Created by Luca on 13/12/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#include "MilovoTables.h"

void LoadTabAgents(SimulationParams &, Agents *, int);
void LoadTabAgentsStyle(SimulationParams &, Agents *, int);
void LoadTabAgentsRelationship(SimulationParams &, Agents *, int);
void LoadTabRecipes(SimulationParams &, Recipes *, Agents *, int);
void LoadTabArtifacts(SimulationParams &, Artifacts *, int);
void LoadTabCompRecipes(SimulationParams &, Recipes *, Artifacts *, int);
void LoadTabCompOperators(SimulationParams &, Recipes *, int);
void LoadTabEnvironment(SimulationParams &, MilovoEnvironment &);
void LoadRequestsTable(SimulationParams &, Requests *, int);
void PrintLoadedAgentsNetwork(Agents *, Recipes *, Artifacts *);
bool LoadEventsTable(string, Events &);


void LoadDataInTextDB(SimulationParams &tmpSimulaParam, Agents *CurrentTabAgents, Recipes *CurrentTabRecipes, Artifacts *CurrentTabArtifacts, 
							 Mil_Int tmpCurrentStep, Requests *CurrentTabRequests, MilovoEnvironment &tmpM_Env)
{
	LoadTabAgents(tmpSimulaParam, CurrentTabAgents, tmpM_Env.GetDebugLevel());
	LoadTabAgentsStyle(tmpSimulaParam, CurrentTabAgents, tmpM_Env.GetDebugLevel());
	LoadTabAgentsRelationship(tmpSimulaParam, CurrentTabAgents, tmpM_Env.GetDebugLevel());
	LoadTabArtifacts(tmpSimulaParam, CurrentTabArtifacts, tmpM_Env.GetDebugLevel());
	LoadTabRecipes(tmpSimulaParam, CurrentTabRecipes, CurrentTabAgents, tmpM_Env.GetDebugLevel());
	LoadTabCompRecipes(tmpSimulaParam, CurrentTabRecipes, CurrentTabArtifacts, tmpM_Env.GetDebugLevel());
	LoadTabCompOperators(tmpSimulaParam, CurrentTabRecipes, tmpM_Env.GetDebugLevel());
	LoadRequestsTable(tmpSimulaParam, CurrentTabRequests, tmpM_Env.GetDebugLevel());
	LoadTabEnvironment(tmpSimulaParam, tmpM_Env);

	if(tmpM_Env.GetDebugLevel() >= 3)
		PrintLoadedAgentsNetwork(CurrentTabAgents, CurrentTabRecipes, CurrentTabArtifacts);
}

void LoadTabAgents(SimulationParams &CurrentSimulaParam, Agents *tmpCurrentTabAgents, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabAgentsDatFile = CurrentSimulaParam.GetWorkingDir() + "TabAgents_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabAgents;
	
	fid_CurrentTabAgents.open(StrCurrentTabAgentsDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabAgents, tmpSingleLine);
	while(getline(fid_CurrentTabAgents, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDAgent(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrActivity(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrGoal(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrNumInnovationSucceded(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrNumInnovationSuccededWithPartner(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrNumInnovationFailed(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrNumInnovationFailedWithPartner(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrNumProjectsSucceded(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrNumProjectsFailed(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrNumTimeSelected(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrBornStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpCurrentTabAgents->insert(make_pair(atol(tmpStrIDAgent.c_str()), Agent(atol(tmpStrIDAgent.c_str()), atof(StrActivity.c_str()), 
																										 atol(StrGoal.c_str()), atol(StrNumInnovationSucceded.c_str()), 
																										 atol(StrNumInnovationSuccededWithPartner.c_str()), 
																										 atol(StrNumInnovationFailed.c_str()), 
																										 atol(StrNumInnovationFailedWithPartner.c_str()), 
																										 atol(StrNumProjectsSucceded.c_str()), 
																										 atol(StrNumProjectsFailed.c_str()), atol(StrNumTimeSelected.c_str()), 
																										 atol(StrBornStep.c_str()))));
	}
	
	fid_CurrentTabAgents.close();
	
	if(tmpCurrentDebugLevel >= 2)
	{
		cout << "Test loading TabAgents at step " << StrStepToLoad.str() << " [begin]" << endl;
		for(Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->begin(); tmpCurrentTabAgentsIter != tmpCurrentTabAgents->end(); tmpCurrentTabAgentsIter++)
			tmpCurrentTabAgentsIter->second.PrintMe();
		cout << "Test loading TabAgents at step " << StrStepToLoad.str() << " [end]" << endl;
	}
}

void LoadTabAgentsStyle(SimulationParams &CurrentSimulaParam, Agents *tmpCurrentTabAgents, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabAgentsStyleDatFile = CurrentSimulaParam.GetWorkingDir() + "TabAgentsStyle_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabAgentsStyle;
	
	fid_CurrentTabAgentsStyle.open(StrCurrentTabAgentsStyleDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabAgentsStyle, tmpSingleLine);
	while(getline(fid_CurrentTabAgentsStyle, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDAgent(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrProbImitation(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrProbJump(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrStartJumpRange(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrEndJumpRange(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrJumpRangeUsed(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrProbDevelopNewGoal(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrInnovationStrategy(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrSelectPartnerMode(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrUseSuppliersChange(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrHowManyNewFriends(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrKnowledgeDecay(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
			
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIncludeZeroAgentInNewFriends(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrSelectGoalInAgentOutput(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrProbGoalFromRequest(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrValidateRecipeOutput(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNProduceFloor(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNProduceCeil(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrAlfaTransactions(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrBetaProjects(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrLambdaTransactions(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrLambdaProjects(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrValueSuccessedProjects(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrValueFailedProjects(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrProjectsDeadLevel(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrMaxRecipesAllowed(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrScaffProb(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrAcceptScaffMinLevel(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrUseDeepSearchGoal(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrChangeSupplierMethod(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrProduceRecipeMethod(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
				
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->find(atol(tmpStrIDAgent.c_str()));
		if((tmpCurrentDebugLevel >= 0) && (tmpCurrentTabAgentsIter == tmpCurrentTabAgents->end()))
		{
			cout << "Error in LoadTabAgentsStyle function: cannot find tmpCurrentTabAgentsIter i tmpCurrentTabAgents: " << tmpStrIDAgent << endl;
			exit(EXIT_FAILURE);
		}
		tmpCurrentTabAgentsIter->second.Style.SetProbImitation(atof(tmpStrProbImitation.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetProbJump(atof(tmpStrProbJump.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetStartJumpRange(atof(tmpStrStartJumpRange.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetEndJumpRange(atof(tmpStrEndJumpRange.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetJumpRangeUsed(atof(tmpStrJumpRangeUsed.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetProbDevelopNewGoal(atof(tmpStrProbDevelopNewGoal.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetInnovationStrategy(atol(tmpStrInnovationStrategy.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetSelectPartnerMode(atol(tmpStrSelectPartnerMode.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetUseSuppliersChange(atof(tmpStrUseSuppliersChange.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetHowManyNewFriends(atol(tmpStrHowManyNewFriends.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetKnowledgeDecay(atol(tmpStrKnowledgeDecay.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetIncludeZeroAgentInNewFriends(atol(tmpStrIncludeZeroAgentInNewFriends.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetSelectGoalInAgentOutput(atol(tmpStrSelectGoalInAgentOutput.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetProbGoalFromRequest(atof(tmpStrProbGoalFromRequest.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetValidateRecipeOutput(atol(tmpStrValidateRecipeOutput.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetNProduceFloor(atol(tmpStrNProduceFloor.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetNProduceCeil(atol(tmpStrNProduceCeil.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetAlfaTransactions(atof(tmpStrAlfaTransactions.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetBetaProjects(atof(tmpStrBetaProjects.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetLambdaTransactions(atof(tmpStrLambdaTransactions.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetLambdaProjects(atof(tmpStrLambdaProjects.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetValueSuccessedProjects(atof(tmpStrValueSuccessedProjects.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetValueFailedProjects(atof(tmpStrValueFailedProjects.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetProjectsDeadLevel(atof(tmpStrProjectsDeadLevel.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetMaxRecipesAllowed(atol(tmpStrMaxRecipesAllowed.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetScaffProb(atof(tmpStrScaffProb.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetAcceptScaffMinLevel(atol(tmpStrAcceptScaffMinLevel.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetUseDeepSearchGoal(atol(tmpStrUseDeepSearchGoal.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetChangeSupplierMethod(atol(tmpStrChangeSupplierMethod.c_str()));
		tmpCurrentTabAgentsIter->second.Style.SetProduceRecipeMethod(atol(tmpStrProduceRecipeMethod.c_str()));
	}
	fid_CurrentTabAgentsStyle.close();
}

void LoadTabAgentsRelationship(SimulationParams &CurrentSimulaParam, Agents *tmpCurrentTabAgents, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabAgentsRelationshipsDatFile = CurrentSimulaParam.GetWorkingDir() + "TabAgentsRelationships_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabAgentsRelationships;
	
	fid_CurrentTabAgentsRelationships.open(StrCurrentTabAgentsRelationshipsDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabAgentsRelationships, tmpSingleLine);
	while(getline(fid_CurrentTabAgentsRelationships, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDAgent(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDAgentPartner(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrTransactions(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrDeltaTransactions(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrProjects(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrDeltaProjects(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrVote(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrAlignedDirectedness(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrHeterogeneity(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrGenerativePotential(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrKnowledgeDecay(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->find(atol(tmpStrIDAgent.c_str()));
		if((tmpCurrentDebugLevel >= 0) && (tmpCurrentTabAgentsIter == tmpCurrentTabAgents->end()))
		{
			cout << "Error in LoadTabAgentsRelationship function: cannot find tmpCurrentTabAgentsIter i tmpCurrentTabAgents: " << tmpStrIDAgent << endl;
			exit(EXIT_FAILURE);
		}
		tmpCurrentTabAgentsIter->second.TabRelationships.insert(make_pair(atol(tmpStrIDAgentPartner.c_str()), 
																								AgentRelationship(atol(tmpStrIDAgentPartner.c_str()), 
																														atof(tmpStrTransactions.c_str()), 
																														atof(tmpStrDeltaTransactions.c_str()), 
																														atof(tmpStrProjects.c_str()), 
																														atof(tmpStrDeltaProjects.c_str()), 
																														atof(tmpStrVote.c_str()), 
																														atol(tmpStrAlignedDirectedness.c_str()), 
																														atof(tmpStrHeterogeneity.c_str()), 
																														atol(tmpStrGenerativePotential.c_str()), 
																														atol(tmpStrKnowledgeDecay.c_str()))));
	}
	fid_CurrentTabAgentsRelationships.close();
	
	if(tmpCurrentDebugLevel >= 2)
	{
		for(Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->begin(); tmpCurrentTabAgentsIter != tmpCurrentTabAgents->end(); tmpCurrentTabAgentsIter++)
		{
			cout << "IDAgent: " << tmpCurrentTabAgentsIter->second.GetID() << endl;
			for(Relationships::iterator TabRelationshipsIter = tmpCurrentTabAgentsIter->second.TabRelationships.begin(); TabRelationshipsIter != tmpCurrentTabAgentsIter->second.TabRelationships.end(); TabRelationshipsIter++)
				cout << "\tPartner: " << TabRelationshipsIter->second.GetIDAgentPartner() << endl;
		}
	}
}

void LoadTabRecipes(SimulationParams &CurrentSimulaParam, Recipes *tmpCurrentTabRecipes, Agents *tmpCurrentTabAgents, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabRecipesDatFile = CurrentSimulaParam.GetWorkingDir() + "TabRecipes_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabRecipes;
	
	fid_CurrentTabRecipes.open(StrCurrentTabRecipesDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabRecipes, tmpSingleLine);
	while(getline(fid_CurrentTabRecipes, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDRecipe(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrStatus(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDAgentOwner(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNProduce(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDArtifactOutput(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpCurrentTabRecipes->insert(make_pair(atol(tmpStrIDRecipe.c_str()), Recipe(atol(tmpStrIDRecipe.c_str()), atol(tmpStrIDAgentOwner.c_str()), 
																											 atol(tmpStrStatus.c_str()), atol(tmpStrIDArtifactOutput.c_str()), 
																											 atol(tmpStrNProduce.c_str()))));

		Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->find(atol(tmpStrIDAgentOwner.c_str()));
		if((tmpCurrentDebugLevel >= 0) && (tmpCurrentTabAgentsIter == tmpCurrentTabAgents->end()))
		{
			cout << "Error in LoadTabRecipes function: cannot find tmpCurrentTabAgentsIter in tmpCurrentTabAgents: " << tmpStrIDAgentOwner << endl;
			exit(EXIT_FAILURE);
		}
		tmpCurrentTabAgentsIter->second.LinkRecipes.push_back(atol(tmpStrIDRecipe.c_str()));
	}
	fid_CurrentTabRecipes.close();
	
	if(tmpCurrentDebugLevel >= 2)
	{
		cout << "Loading TabRecipes at Step: " << StrStepToLoad.str() << " [begin]" << endl;
		for(Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->begin(); tmpCurrentTabRecipesIter != tmpCurrentTabRecipes->end(); tmpCurrentTabRecipesIter++)
			cout << "IDRecipe: " << tmpCurrentTabRecipesIter->second.GetID() << endl;
		cout << "Loading TabRecipes at Step: " << StrStepToLoad.str() << " [end]" << endl;
	}
}

void LoadTabArtifacts(SimulationParams &CurrentSimulaParam, Artifacts *tmpCurrentTabArtifacts, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabArtifactsDatFile = CurrentSimulaParam.GetWorkingDir() + "TabArtifacts_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabArtifacts;
	
	fid_CurrentTabArtifacts.open(StrCurrentTabArtifactsDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabArtifacts, tmpSingleLine);
	while(getline(fid_CurrentTabArtifacts, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDArtifact(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrName(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrStatus(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDAgentOwner(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrAmount(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrAmountCeil(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDRecipeOwner(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrBuyers(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrBornStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpCurrentTabArtifacts->insert(make_pair(atol(tmpStrIDArtifact.c_str()), Artifact(atol(tmpStrIDArtifact.c_str()), atol(tmpStrName.c_str()), 
																													 atol(tmpStrIDRecipeOwner.c_str()), atol(tmpStrIDAgentOwner.c_str()), 
																													 atol(tmpStrStatus.c_str()), atol(tmpStrAmount.c_str()), 
																													 atol(tmpStrAmountCeil.c_str()), atol(tmpStrBuyers.c_str()), 
																													 atol(tmpStrBornStep.c_str()))));
	}
	
	fid_CurrentTabArtifacts.close();
	
	if(tmpCurrentDebugLevel >= 2)
	{
		cout << "Loading TabArtifacts at Step: " << StrStepToLoad.str() << " [begin]" << endl;
		for(Artifacts::iterator tmpCurrentTabArtifactsIter = tmpCurrentTabArtifacts->begin(); tmpCurrentTabArtifactsIter != tmpCurrentTabArtifacts->end(); tmpCurrentTabArtifactsIter++)
			cout << "IDArtifact: " << tmpCurrentTabArtifactsIter->second.GetID() << endl;
		cout << "Loading TabArtifacts at Step: " << StrStepToLoad.str() << " [end]" << endl;
	}
}

void LoadTabCompRecipes(SimulationParams &CurrentSimulaParam, Recipes *tmpCurrentTabRecipes, Artifacts *tmpCurrentTabArtifacts, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabCompRecipesDatFile = CurrentSimulaParam.GetWorkingDir() + "TabCompRecipes_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabCompRecipes;
	
	fid_CurrentTabCompRecipes.open(StrCurrentTabCompRecipesDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabCompRecipes, tmpSingleLine);
	while(getline(fid_CurrentTabCompRecipes, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDRecipe(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDArtifact(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->find(atol(tmpStrIDRecipe.c_str()));
		if((tmpCurrentDebugLevel >= 0) && (tmpCurrentTabRecipesIter == tmpCurrentTabRecipes->end()))
		{
			cout << "Error in LoadTabCompRecipes function: cannot find tmpCurrentTabRecipesIter in tmpCurrentTabRecipes: " << tmpStrIDRecipe << endl;
			exit(EXIT_FAILURE);
		}
		tmpCurrentTabRecipesIter->second.LinksIDArtifacts.push_back(atol(tmpStrIDArtifact.c_str()));
		
		Artifacts::iterator tmpCurrentTabArtifactsIter = tmpCurrentTabArtifacts->find(atol(tmpStrIDArtifact.c_str()));
		if((tmpCurrentDebugLevel >= 0) && (tmpCurrentTabArtifactsIter == tmpCurrentTabArtifacts->end()))
			tmpCurrentTabRecipesIter->second.LinksNameArtifacts.push_back(-1);
		else tmpCurrentTabRecipesIter->second.LinksNameArtifacts.push_back(tmpCurrentTabArtifactsIter->second.GetName());
	}
	
	fid_CurrentTabCompRecipes.close();
	
	if(tmpCurrentDebugLevel >= 2)
	{
		cout << "Loading TabCompRecipes at Step: " << StrStepToLoad.str() << " [begin]" << endl;
		for(Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->begin(); tmpCurrentTabRecipesIter != tmpCurrentTabRecipes->end(); tmpCurrentTabRecipesIter++)
		{
			cout << "IDRecipe: " << tmpCurrentTabRecipesIter->second.GetID() << endl;
			for(list<Mil_Int>::iterator LinksIDArtifactsIter = tmpCurrentTabRecipesIter->second.LinksIDArtifacts.begin(); LinksIDArtifactsIter != tmpCurrentTabRecipesIter->second.LinksIDArtifacts.end(); LinksIDArtifactsIter++)
				cout << "\tIDArtInput: " << (Mil_Int) *LinksIDArtifactsIter << endl;
		}
		cout << "Loading TabCompRecipes at Step: " << StrStepToLoad.str() << " [end]" << endl;
	}
}

void LoadTabCompOperators(SimulationParams &CurrentSimulaParam, Recipes *tmpCurrentTabRecipes, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabCompOperatorsDatFile = CurrentSimulaParam.GetWorkingDir() + "TabCompOperators_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabCompOperators;
	
	fid_CurrentTabCompOperators.open(StrCurrentTabCompOperatorsDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabCompOperators, tmpSingleLine);
	while(getline(fid_CurrentTabCompOperators, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDRecipe(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrIDOperator(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->find(atol(tmpStrIDRecipe.c_str()));
		if((tmpCurrentDebugLevel >= 0) && (tmpCurrentTabRecipesIter == tmpCurrentTabRecipes->end()))
		{
			cout << "Error in LoadTabCompOperators function: cannot find tmpCurrentTabRecipesIter in tmpCurrentTabRecipes: " << tmpStrIDRecipe << endl;
			exit(EXIT_FAILURE);
		}
		tmpCurrentTabRecipesIter->second.LinksOperators.push_back(atol(tmpStrIDOperator.c_str()));
	}
	
	fid_CurrentTabCompOperators.close();
	
	if(tmpCurrentDebugLevel >= 2)
	{
		cout << "Loading TabCompOperators at Step: " << StrStepToLoad.str() << " [begin]" << endl;
		for(Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->begin(); tmpCurrentTabRecipesIter != tmpCurrentTabRecipes->end(); tmpCurrentTabRecipesIter++)
		{
			cout << "IDRecipe: " << tmpCurrentTabRecipesIter->second.GetID() << endl;
			for(list<Mil_Int>::iterator LinksOperatorsIter = tmpCurrentTabRecipesIter->second.LinksOperators.begin(); LinksOperatorsIter != tmpCurrentTabRecipesIter->second.LinksOperators.end(); LinksOperatorsIter++)
				cout << "\tIDOperator: " << (Mil_Int) *LinksOperatorsIter << endl;
		}
		cout << "Loading TabCompOperators at Step: " << StrStepToLoad.str() << " [end]" << endl;
	}
}

void LoadTabEnvironment(SimulationParams &CurrentSimulaParam, MilovoEnvironment &tmpCurrentM_Env)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabEnvironmentDatFile = CurrentSimulaParam.GetWorkingDir() + "TabEnvironment_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabEnvironment;
	
	fid_CurrentTabEnvironment.open(StrCurrentTabEnvironmentDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabEnvironment, tmpSingleLine);
	while(getline(fid_CurrentTabEnvironment, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNumInnovationSucceded(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNumInnovationFailed(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNumAgentsBorn(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNumAgentsDeadByMarket(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNumAgentsDeadByZeroRecipes(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNumRecipesDeadByProduction(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrNumRecipesDeadByMarket(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string tmpStrGrowProbability(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpCurrentM_Env.SetNumInnovationSucceded(atol(tmpStrNumInnovationSucceded.c_str()));
		tmpCurrentM_Env.SetNumInnovationFailed(atol(tmpStrNumInnovationFailed.c_str()));
		tmpCurrentM_Env.SetNumAgentsBorn(atol(tmpStrNumAgentsBorn.c_str()));
		tmpCurrentM_Env.SetNumAgentsDeadByMarket(atol(tmpStrNumAgentsDeadByMarket.c_str()));
		tmpCurrentM_Env.SetNumAgentsDeadByZeroRecipes(atol(tmpStrNumAgentsDeadByZeroRecipes.c_str()));
		tmpCurrentM_Env.SetNumRecipesDeadByProduction(atol(tmpStrNumRecipesDeadByProduction.c_str()));
		tmpCurrentM_Env.SetNumRecipesDeadByMarket(atol(tmpStrNumRecipesDeadByMarket.c_str()));
		tmpCurrentM_Env.SetGrowProbability(atof(tmpStrGrowProbability.c_str()));
	}

	fid_CurrentTabEnvironment.close();
}

void PrintLoadedAgentsNetwork(Agents *tmpCurrentTabAgents, Recipes *tmpCurrentTabRecipes, Artifacts *tmpCurrentTabArtifacts)
{
	for(Agents::iterator tmpCurrentTabAgentsIter = tmpCurrentTabAgents->begin(); tmpCurrentTabAgentsIter != tmpCurrentTabAgents->end(); tmpCurrentTabAgentsIter++)
	{
		cout << "IDAgent: " << tmpCurrentTabAgentsIter->second.GetID() << endl;
		for(list<Mil_Int>::iterator LinkRecipesIter = tmpCurrentTabAgentsIter->second.LinkRecipes.begin(); LinkRecipesIter != tmpCurrentTabAgentsIter->second.LinkRecipes.end(); LinkRecipesIter++)
		{
			Mil_Int tmpIDRecipeToAnalize = *LinkRecipesIter;
			Recipes::iterator tmpCurrentTabRecipesIter = tmpCurrentTabRecipes->find(tmpIDRecipeToAnalize);
			if(tmpCurrentTabRecipesIter == tmpCurrentTabRecipes->end())
				cout << "\tIDRecipeLink: " << tmpIDRecipeToAnalize << " Not Found" << endl;
			else
			{
				cout << "\tIDRecipeLink: " << tmpIDRecipeToAnalize << " - Found in TabRecipes: " << tmpCurrentTabRecipesIter->second.GetID() << endl;
				for(list<Mil_Int>::iterator LinksIDArtifactsIter = tmpCurrentTabRecipesIter->second.LinksIDArtifacts.begin(); LinksIDArtifactsIter != tmpCurrentTabRecipesIter->second.LinksIDArtifacts.end(); LinksIDArtifactsIter++)
				{
					Mil_Int tmpIDArtifactToAnalize = *LinksIDArtifactsIter;
					Artifacts::iterator tmpCurrentTabArtifactsIter = tmpCurrentTabArtifacts->find(tmpIDArtifactToAnalize);
					if(tmpCurrentTabArtifactsIter == tmpCurrentTabArtifacts->end())
						cout << "\t\tIDArtifactLink: " << tmpIDArtifactToAnalize << " Not Found" << endl;
					else cout << "\t\tIDArtifactLink: " << tmpIDArtifactToAnalize << " - Found in TabArtifacts: " << 
						tmpCurrentTabArtifactsIter->second.GetID() << " Name: " << tmpCurrentTabArtifactsIter->second.GetName() << endl;
				}
			}
		}
	}
}

bool LoadEventsTable(string strPath, Events &tmpTabEvents)
{
	string tmpFileEventsTable(strPath);
	ifstream fid_EventsTable(tmpFileEventsTable.c_str());
	
	string tmpSingleLine;
	getline(fid_EventsTable, tmpSingleLine);
	while(getline(fid_EventsTable, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string StrIDEvent(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrEventCode(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrEventStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabEvents.insert(make_pair(tmpTabEvents.size(),Event(atol(StrIDEvent.c_str()), atol(StrEventCode.c_str()), 
																				  atol(StrEventStep.c_str()))));
	}
	
	return true;
}

void LoadRequestsTable(SimulationParams &CurrentSimulaParam, Requests *tmpCurrentTabRequests, int tmpCurrentDebugLevel)
{
	ostringstream StrStepToLoad;
	StrStepToLoad << CurrentSimulaParam.GetNumFirstStep();
	string StrCurrentTabRequestsDatFile = CurrentSimulaParam.GetWorkingDir() + "TabRequest_Step" + StrStepToLoad.str() + ".csv";	
	ifstream fid_CurrentTabRequests;
	
	fid_CurrentTabRequests.open(StrCurrentTabRequestsDatFile.c_str(), ios::in);
	string tmpSingleLine;
	getline(fid_CurrentTabRequests, tmpSingleLine);
	while(getline(fid_CurrentTabRequests, tmpSingleLine))
	{
		Mil_Int tmpTabPos = tmpSingleLine.find("\t");
		string StrIDrequest(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrArtifactName(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrIDAgentOwner(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrRequestStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrChecked(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrIDAgentChecked(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStepChecked(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		tmpTabPos = tmpSingleLine.find("\t");
		string StrStep(tmpSingleLine, 0, tmpTabPos);
		tmpSingleLine.assign(tmpSingleLine, tmpTabPos + 1, tmpSingleLine.size());
		
		bool tmpChecked;
		if(atol(StrChecked.c_str()) == 1)
			tmpChecked = true;
		else tmpChecked = false;
		
		tmpCurrentTabRequests->insert(make_pair(atol(StrIDrequest.c_str()), Request(atol(StrIDrequest.c_str()), 
																											 atol(StrIDAgentOwner.c_str()),
																											 atol(StrArtifactName.c_str()),
																											 atol(StrRequestStep.c_str()),
																											 atol(StrIDAgentChecked.c_str()),
																											 tmpChecked,
																											 atol(StrStepChecked.c_str()))));
	}
	
	fid_CurrentTabRequests.close();
}

